

// Test program for double-ended queues.
// No changes allowed.

#include "DoubleEnded.h"
#include <iostream>
using namespace std;

const int N = 1787;
const int M = 2357;

int main( )
{
    DoubleEnded<int> q;
    int minVal1, minVal2, maxVal1, maxVal2;
    int i, j;

    for( i = N; i != 0; i = ( i + N ) % M )
        q.insert( i );

    cout << "Completed first round of insertions" << endl;

    for( j = 1; !q.isEmpty( ); j += 2 )
    {
        minVal1 = q.findMin( );
        q.deleteMin( );
        q.deleteMin( minVal2 );
        if( minVal1 != j || minVal2 != j+1 )
            cout << "OOPS!!!!!" << minVal1 << " " << minVal2 << " "
                                << j << " " << (j+1) << endl;

        maxVal1 = q.findMax( );
        q.deleteMax( );
        q.deleteMax( maxVal2 );
        if( maxVal1 != M - j || maxVal2 != M - j - 1 )
            cout << "OOPS!!!!!" << maxVal1 << " " << maxVal2 << " "
                                << (M-j) << " " << (M-j-1) << endl;
    }

    cout << "Completed first round of deletions" << endl;

    for( i = N; i != 0; i = ( i + N ) % M )
        q.insert( i );

    cout << "Completed second round of insertions" << endl;
    for( i = 0; i < M - 5; i += 2 )
    {
        q.deleteMin( ); q.deleteMax( );
    }

    for( ; !q.isEmpty( ); q.deleteMin( ), q.deleteMax( ) )
        cout << q.findMin( ) << endl << q.findMax( ) << endl;

    cout << "Program end reached" << endl;

    return 0;
} 
